from chernc.treediff.gumtree.actions.model.action import Action
from chernc.treediff.gumtree.tree.tree import TreeLike


class Addition(Action):
    def __init__(self, node: TreeLike, parent: TreeLike, pos: int):
        super().__init__(node)
        self.parent = parent
        self.pos = pos

    def get_parent(self) -> TreeLike:
        return self.parent

    def get_position(self) -> int:
        return self.pos

    def __str__(self) -> str:
        return f"===\n{self.get_name()}\n---\n{self.node}\nto\n{self.parent if self.parent else 'root'}\nat {self.pos}"

    def __eq__(self, other: object) -> bool:
        if not super().__eq__(other):
            return False
        if not isinstance(other, Addition):
            return False
        a = other  # Type-casting to Addition
        return self.parent == a.parent and self.pos == a.pos
